<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2018/9/27 0027
 * Time: 上午 10:57
 */
namespace app\common\validate;

use app\lib\exception\ParameterException;

class CreateAdvertise extends BaseValidate{
    protected $rule = [
        'advertise' => 'checkadvertises',
        'advertiseLocalId' => 'require|isNotEmpty',
        'storeId' => 'require|isNotEmpty'

    ];

    protected $message = [
        'advertiseLocalId' => '广告位ID不能为空!',
        'storeId' => '店铺ID不能为空'

    ];
    protected $singRule = [
        'advertiseCost' => 'require|isNotEmpty',
        'advertiseUrlStatus' => 'require|isNotEmptyz',
        'advertiseImgUrl' => 'require|isNotEmpty',
        'advertiseTitle' => 'require|isNotEmpty',
        'circleTime' => 'require|isNotEmpty'
    ];

    protected function checkadvertises($values){
        if(!is_array($values) || empty($values)){
            throw new ParameterException([
                'msg' => '广告参数不合法'
            ]);
        }
        $this->checkadvertise($values);

        return true;
    }

    protected function checkadvertise($value){
        $validate = new BaseValidate($this->singRule);
        $result = $validate->check($value);
        if(!$result){
            throw new ParameterException([
                'msg' => '广告参数错误'
            ]);
        }
    }

}